#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>

int main()
{
	int n;
	scanf("%d", &n);

	int i;
	int hole, dpt;
	int y, m, d;
	for (i = 1; i <= n; i++)
	{
		scanf("%6d%4d%2d%2d%4d", &hole, &y, &m, &d, &dpt);
		printf("%d-%02d-%02d\n", y, m, d);
	}
	return 0;
}